import { ui } from "./../ui/layaMaxUI";
import CommonConstant from "../constant/CommonConstant";
import GameConfig from "../GameConfig";
import EnumData from "../Enum/EnumData";
import GameFacade from "../GameFacade";

class RotationScript extends Laya.Script3D {
	private _lastMouseX: number;
	private _mouseDown: boolean = false;
	private _rotate: Laya.Vector3 = new Laya.Vector3();

	model: Laya.Sprite3D;
	constructor() {
		super();
		this._lastMouseX = 0.0;
		this._mouseDown = false;
		this._rotate = new Laya.Vector3();
		this.model = null;
		Laya.stage.on(Laya.Event.MOUSE_DOWN, this, function () {
			this._mouseDown = true;
			this._lastMouseX = Laya.MouseManager.instance.mouseX;
		});
		Laya.stage.on(Laya.Event.MOUSE_UP, this, function () {
			this._mouseDown = false;
		});

	}
	onUpdate() {
		if (this._mouseDown) {
			var deltaX = Laya.MouseManager.instance.mouseX - this._lastMouseX;
			this._rotate.y = deltaX * 0.2;
			this.model.transform.rotate(this._rotate, false, false);
			this._lastMouseX = Laya.MouseManager.instance.mouseX;
		}
	}
}

export default class GameUI extends ui.test.TestSceneUI {

	constructor() {
		console.log("GameUI");
		super();

		// Laya.loader.create(CommonConstant._scenePatLv1,
		// 	Laya.Handler.create(this,  this.onComplete),
		// 	null,
		// 	null, );
	}

	private onComplete(scene: Laya.Scene3D): void {

		// debug.log(" debug使用loader加载");
		Laya.stage.addChild(scene);
		// var model: Laya.Sprite3D = <Laya.Sprite3D>scene.getChildByName("Rotate");
		// var rotationScript: RotationScript = model.addComponent(RotationScript);
		// scene.ambientColor = new Laya.Vector3(0.6,0,0);
		// rotationScript.model = model;
		// let propData = window.gameFacade.ConfigMng.GetGamePropDataById(1);
		// console.log(propData);
	}

	
}